<?php
/**
 * Project: Recipe
 * File: MenuItemModel.class.php
 * Author: Xnfy520@gmail.com
 * Date: 12-5-7
 * Time: 下午3:28
 */

class MenuItemModel extends RelationModel{

	protected $_validate = array(
		array('name', 'require', '菜单项名称不能为空', 1, 'regex', 3),
		array('link', 'require', '链接地址不能为空', 1, 'regex', 3),
		array('sort', 'number', '排序必须为数字', 1, 'regex', 3),
		array('menuid', 'require', '菜单ID不能为空', 1, 'regex', 1),
		array('componentid', 'require', '组件ID不能为空', 1, 'regex', 1),
		array('selectid', 'require', '选择ID不能为空', 1, 'regex', 1),
	);

	protected $_auto = array(
		array('path', '_getpath', 3, 'callback'),
	);

	function _getpath(){
		$pid = isset($_POST['pid']) ? $_POST['pid'] : 0;
		if($pid==0){
			return 0;
		}else{
			$id = $_POST['id'];
			$pinfo = $this->find($pid);
			$path = $pinfo['path'].'-'.$pinfo['id'];
			return $path;
		}

	}

}